/**
 * Created by zf900 on 2017/4/20.
 */
/*
 下面是个立即调用的方法表达式，它的格式是: (function() {}());，即匿名函数定义后加上()，外围再用小括号括起来，后面再加逗号完成表达式。
 */
(function () {
	/**
	 * 定义hotel的对象字面量
	 * @type {{}}
	 */
	var hotel = {
		name: 'pack',
		roomRate: 240,
		discount: 15,
		offerPrice: function () {
			var offerRate = this.roomRate * ((100 - this.discount) / 100);

			return offerRate;
		}
	}

	var hotelName, roomRate, specialRate;
	hotelName = document.getElementById('hotel_name');
	roomRate = document.getElementById('room_rate');
	specialRate = document.getElementById('special_rate');

	hotelName.textContent = hotel.name;
	roomRate.textContent = '$' + hotel.roomRate.toFixed(2);
	specialRate.textContent = '$' +hotel.offerPrice();	//注意此处行尾的小括号，这儿要的是函数结果需立即执行，否则会输出函数内容

	var expireMessage;
	var today;
	var elEnds;

	function offerExpires(today) {
		var weekFromToday, day, date, month, year, dayNames, monthNames;
		weekFromToday = new Date(today.getTime() + 7 * 24 * 60 * 60 * 1000);	//添加七天，得到七天后的日期
		dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
		monthNames = ['January', 'Febuary', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
		day = dayNames[weekFromToday.getDay()];
		date = weekFromToday.getDate();
		month = monthNames[weekFromToday.getMonth()];
		year = weekFromToday.getFullYear();

		expireMessage = 'Offer expires next ';
		expireMessage += day + ' <br />(' + date + ' ' + month + ' ' + year + ')';

		return expireMessage;
	}

	today = new Date();
	elEnds = document.getElementById('offerEnds');
	elEnds.innerHTML = offerExpires(today);
}());
